@using CodeGenerator
@using RazorLight
@using BXJG.Common;
@using BXJG.Common.Extensions;
@inherits TemplatePage<ExecuteContext>
@{
    DisableEncoding = true;//禁止html编码，因为我们是做代码生成器
}
@("@page") "/@(Model.Model.Name)"

@@using @(Model.Model.ApplicationShareNamespace)

@@attribute [ReuseTabsPage(Title = "@(Model.Model.DisplayName)")]
@@attribute [Authorize(@(Model.Model.PermissionNameGetConst))]

@@inherits ListBaseComponent<@(Model.Model.DtoName), @(Model.Model.PrimaryFieldCSharpType), PagedAndSortedResultRequest<@(Model.Model.ConditionName)>>

<Flex Gap="small" Vertical Justify="space-between">
    @@* 顶部工具栏 *@@
    <Flex Justify="space-between">
        @@* 左侧 *@@
        <Flex Gap="small">
            @@if (createIsGranted)
            {
                <Button Type="@@ButtonType.Primary" Icon="@@IconType.Outline.Plus" OnClick="BtnCreateClick" Disabled="IsBusy">新增</Button>
            }
            @@if (deleteIsGranted)
            {
                @* 由于多选除了删除可能做其它操作，可能失误，所以虽然这里删除是两个步骤，依然加个确认比较靠谱 *@
                <Popconfirm Title="确定删除已选择的项吗?" OnConfirm="BtnDeleteClick">
                    <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Clear" Danger Disabled="ShouldDisableDelete" Loading="isDeleting">删除</Button>
                </Popconfirm>
            }
        </Flex>
        @@* 右侧 *@@
        <Flex Gap="small">
@foreach (var field in Model.Model.ConditionRangeFields)
{
    if(field.CSharpTypeIsDateTime){
            <RangePicker TValue="@(field.CSharpType)?[]" @@bind-Value="@field.ConditionRangeName" Placeholder=@@(new string[] { "开始@(field.DisplayName)", "结束@(field.DisplayName)" }) @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
    }
    else if(field.CSharpTypeIsNumber){
            <AntDesign.InputNumber @@bind-Value="GetAllInput.Filter.@field.ConditionRangeMin" PlaceHolder="最小@(field.DisplayName)" @(field.NumberPrecision.HasValue?@$"Precision=""{field.NumberPrecision}""":"") @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
            <AntDesign.InputNumber @@bind-Value="GetAllInput.Filter.@field.ConditionRangeMax" PlaceHolder="最大@(field.DisplayName)" @(field.NumberPrecision.HasValue?@$"Precision=""{field.NumberPrecision}""":"") @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
    }
}
@foreach (var field in Model.Model.ConditionNormalFields)
{
            <Input @@bind-Value="GetAllInput.Filter.@field.Name" PlaceHolder="@(field.DisplayName)" @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
}
            <div style="width:14.5rem;">
                <Search Placeholder="@(string.Join("/", Model.Model.ConditionStringFields.Select(x=>x.DisplayName)))等关键字..." @@bind-Value="Keywords" OnChange="BtnSearchClick" AllowClear="true" Disabled="IsBusy" />
            </div>
            <Tooltip Title="清空条件">
                <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Clear" OnClick="BtnClearFilterClick" Disabled="IsBusy"></Button>
            </Tooltip>
            <Tooltip Title="刷新">
                <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Reload" OnClick="BtnRefreshClick" Disabled="IsBusy"></Button>
            </Tooltip>
        </Flex>

    </Flex>

    @@* 表格 *@@
    <Table @@ref="table"
           TItem="@(Model.Model.DtoName)"
           Total="TotalCount"
           @@bind-SelectedRows="SelectedItems"
           OnChange="OnQuery"
           DataSource="Items"
           PageIndex="PageIndex"
           PageSize="PageSize"
           Loading="IsLoading"
           RowClassName="@@(r=>r.RowIndex%2==0?"even":"odd")"
           RemoteDataSource="true"
           RowKey="x=>x.Id"
           OnRow="OnRow"
           Size="TableSize.Small"
           Bordered="true"
           ScrollY="71.5vh"
           ScrollX="1000px">

        <Selection Width="50" Fixed="left" />
        <Column TData=@(Model.Model.DtoName) Title="行号" Width="60" Fixed="left">
            @@(PageSize * (PageIndex - 1) + Items.IndexOf(context) + 1)
        </Column>

@foreach (var field in Model.Model.NormalFields){
    @if(field.CSharpType=="bool"){
        <PropertyColumn Property="c=>c.@(field.Name)" ShowSorterTooltip="false"  @(field.IsSort?"Sortable":"") Width="5rem" @(field.FixedLeft==true?@"Fixed=""left""":(field.FixedLeft==false?@"Fixed=""right""":"")) Align="ColumnAlign.Center">
            <Switch @@bind-Value="@@context.@(field.Name)" Size="@@InputSize.Small" Disabled="true"></Switch>
        </PropertyColumn>
    }else{
        <PropertyColumn Property="c=>c.@(field.Name)" @(field.IsSort?@"Sortable=""true""":"") ShowSorterTooltip="false" @(field.Width.IsNullOrWhiteSpaceBXJG()?"":@$"Width=""{field.Width}""") @(field.FixedLeft==true?@"Fixed=""left""":(field.FixedLeft==false?@"Fixed=""right""":"")) @(field.Position==true?"":(field.FixedLeft==false?@"Align=ColumnAlign.Right":@"Align=""ColumnAlign.Center"""))/>        
    }
}
        <ActionColumn Title="操作" Width="160" Fixed="right" Align="ColumnAlign.Center">
            <ButtonGroup Size="@@ButtonSize.Small">
                <Button Size="@@ButtonSize.Small" Type="@@ButtonType.Primary" OnClick="x=>BtnItemDetailClick(context)">详情</Button><br />
                @@if (updateIsGranted)
                {
                    <Button Size="@@ButtonSize.Small" OnClick="x=>BtnItemEditClick(context)">修改</Button>
                }
                @@if (deleteIsGranted)
                {
                    <Popconfirm Title="确定删除此项吗?"
                                OnConfirm="()=>BtnDeleteItemClick(context)">
                        <Button Size="@@ButtonSize.Small" Danger="true">删除</Button>
                    </Popconfirm>
                }
            </ButtonGroup>
        </ActionColumn>
    </Table>
</Flex>

@@*新增弹窗*@@
@@{
    RenderFragment renderFragment = @@<Template>
        <SectionOutlet SectionName=@@($"{this.GetHashCode()}-create-btns") />
        <Button OnClick="CloseCreateDialog">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true" 
       Footer="renderFragment" 
       @@bind-Visible="isCreateDialogVisible" 
       Draggable="true"
       Class="frm-dal" 
       AfterClose="AfterCloseDialog">
    <TitleTemplate>
        <Icon Type="plus" Theme="outline" />新增@@(FuncName)
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName=@@($"{this.GetHashCode()}-create-body") />
        <@(Model.Model.BlazorClientNamespace).Create OnAddEnd="OnAddEnd" Master=@@(this.GetHashCode()) />
    </ChildContent>
</Modal>

@@*修改和详情弹窗*@@
@@{
    RenderFragment renderFragment1 = @@<Template>
        <SectionOutlet SectionName=@@($"{this.GetHashCode()}-detail-update-btns") />
        <Button OnClick="CloseUpdateOrDetail">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose
       @@bind-Visible="isShowDetailUpdate"
       Draggable="true"
       Title="详情"
       Width="@@("50vw")"
       Class="frm-dal"
       Maximizable="false"
       AfterClose="AfterCloseDialog"
       Footer="renderFragment1"
       DefaultMaximized="false"
       MaxBodyHeight="86vh">
    <TitleTemplate>
        <SectionOutlet SectionName=@@($"{this.GetHashCode()}-detail-update-title") />
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName=@@($"{this.GetHashCode()}-detail-update-body") />
        <@(Model.Model.BlazorClientNamespace).DetailUpdate Id="detailUpdateId" IsEdit="isEdit" OnDeleted="DetailDeleted" OnUpdated="DetailUpdated" Master="GetHashCode()" />
    </ChildContent>
</Modal>